package com.rockcent.mall.lib.repository;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.rockcent.common.common.PageResult;
import com.rockcent.common.common.SQLListDoing;
import com.rockcent.mall.lib.domain.ProductCategories;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by zhangjh on 2016/11/3.
 */
@Repository
public class MerchantProductCategoriesRepositoryImpl implements MerchantProductCategoriesRepositoryCustom {
    private static final Logger log = LoggerFactory.getLogger(MerchantProductCategoriesRepositoryImpl.class);

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public List<ProductCategories> findByCategoryIdLimit(Long categoryId) {
        SQLListDoing<ProductCategories> doing = (sql, fields, params, typeReferenceMap)->{
            sql.append("SELECT pc.* FROM product_categories pc WHERE pc.category_id = :categoryId LIMIT 0,10 ");
            params.put("categoryId",categoryId);
        };
        return doing.go(ProductCategories.class, objectMapper , jdbcTemplate, log);
    }
}
